from datetime import timedelta
from redis import StrictRedis


class Config():
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/InfoNews"
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # 是否追踪数据库变化
    REDIS_HOST = "127.0.0.1"  # redis的ip
    REDIS_PORT = 6379  # redis的端口号
    SESSION_TYPE = "redis"  # session存储的数据库类型
    SESSION_USE_SIGNER = True  # 是对cookie中存储的session进行加密 (需要使用app秘钥
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # 设置session存储使用的redis连接对象
    SECRET_KEY = "DxY3z7jndzYaiY1ndZh+OJOv800zHpRZiWwwNBjC5PAQ1IEMMcWqiyQ8xn2lviMg"  # 应用秘钥
    PERMANENT_SESSION_LIFETIME = timedelta(days=7)  # 设置session的持久时间,session会默认进行持久化
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True


class DevelopConfig(Config): # 定义开发环境的配置
    DEBUG = True


class ProductConfig(Config): # 定义生产环境的配置
    DEBUG = False


config_dict = {
    "dev":DevelopConfig,
    "pro":ProductConfig
}
